﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.Text;
using Maticsoft.Common;
using System.Collections.Generic;

namespace Lawyer.Web.Admin
{
    public partial class admin_activitytpyeupdate : System.Web.UI.Page
    {
        //protected string TypeID = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                    ShowInfo();

            }
        }

        private void ShowInfo()
        {
            string TypeID = null;
            if (Request.Params["type"] != null && Request.Params["type"].Trim() != "")
            {
                TypeID = Request.Params["type"];

                Lawyer.BLL.ActivityTypeInfo bll = new Lawyer.BLL.ActivityTypeInfo();
                Lawyer.Model.ActivityTypeInfo model = bll.GetModel(TypeID);
                lbTypeID.Text = model.TypeID;
                this.txtType.Text = model.TypeName;
            }
        }

        Lawyer.BLL.ActivityInfo activitybll = new Lawyer.BLL.ActivityInfo();
        Lawyer.BLL.ActivityTypeInfo bll = new Lawyer.BLL.ActivityTypeInfo();

        protected void btnSubmit_Click(object sender, EventArgs e)
        {

            string strErr = "";

            string TypeName = this.txtType.Text;
            string TypeID = this.lbTypeID.Text;

            Lawyer.Model.ActivityTypeInfo model = new Lawyer.Model.ActivityTypeInfo();


            model.TypeID = TypeID;
            model.TypeName = TypeName;
            string strWhere = " Type = '" + TypeName + "'";

            List<Model.ActivityInfo> list = activitybll.GetModelList(strWhere);
            string js = "";
            if (list != null && list.Count != 0)
            {
                js =
                @"if(confirm('There are some activities related with this type !')){
                    parent.location.reload();
                }";
            }
            else
            {
                if (bll.Update(model))
                {
                    js =
                    @"if(confirm('update successfully!')){
                        parent.location.reload();
                    }";  
                }
                else
                {
                    js =
                    @"if(confirm('update failed!')){
                        parent.location.reload();
                    }";
                }
            }
            ScriptManager.RegisterStartupScript(this, this.GetType(), "a", js, true);
        }
    }
}
